/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminFrame.java
 *
 * Created on Oct 18, 2010, 4:12:04 PM
 */
package view.admin;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.SwingUtilities;

import command.CommandFactory;

import model.Player;
import model.PlaylistRecord;
import observer.UpdateObserver;
import view.PlayerCanvas;
import config.Helper;
import config.Settings;
import controller.Command;
import controller.Initializer;
import controller.NewPlayerChecker;
import controller.UpdateChecker;
import data.HttpRequest;

/**
 * 
 * @author Yang Wang <yang@digitalmenubox.com>
 */
public final class AdminFrame extends javax.swing.JFrame implements UpdateObserver, WindowListener {

	private static AdminFrame instance = new AdminFrame();
	private boolean authenticated = false;

	/** Creates new form AdminFrame */
	private AdminFrame() {
		initComponents();
		setComponentValues();
		this.addWindowListener(this);

	}

	public static AdminFrame getInstance() {
		return instance;
	}

	private void setComponentValues() {
		this.mysqlServerTextField.setText(Settings.getLocalMysqlServer());
		this.mysqlDatabaseNameTextField.setText(Settings.getLocalMysqlDatabase());
		this.mysqlUsernameTextField.setText(Settings.getLocalMysqlUsername());
		this.mysqlPasswordTextField.setText(Settings.getLocalMysqlPassword());
		this.dmbFtpServerTextField.setText(Settings.getWebtoolFtpHost());
		this.dmbFtpUsernameTextField.setText(Settings.getWebtoolFtpUser());
		this.dmbFtpPasswordTextField.setText(Settings.getWebtoolFtpPassword());
		this.boxIdNumberField.setValue(Settings.getBoxId());
		this.scaleNumberField.setValue(Settings.getScale());
		this.playerWidthNumberField.setValue(Settings.getPlayerWidth());
		this.playerHeightNumberField.setValue(Settings.getPlayerHeight());
		this.playerVersionField.setText(Double.toString(Settings.VERSION));
		this.numErrors.setText(Integer.toString(Settings.getNumberOfErrorsOccured()));
		this.connectionGroup.add(this.ftpConnectionRadioButton);
		this.connectionGroup.add(this.httpConnectionRadioButton);
		if (Settings.getConnectionType() == Settings.FTP_CONNECTION) {
			this.ftpConnectionRadioButton.setSelected(true);
		} else {
			this.httpConnectionRadioButton.setSelected(true);
		}
		this.buttonGroup1.add(this.autoboxRadioButton);
		this.buttonGroup1.add(this.menuboxRadioButton);
		if (Settings.getBoxType() == Settings.BOX_TYPE_MENUBOX) {
			this.menuboxRadioButton.setSelected(true);
		} else if (Settings.getBoxType() == Settings.BOX_TYPE_AUTOBOX) {
			this.autoboxRadioButton.setSelected(true);
		}
		// this.playlistRecordList.setCellRenderer(renderer);

	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		connectionGroup = new javax.swing.ButtonGroup();
		buttonGroup1 = new javax.swing.ButtonGroup();
		buttonGroup2 = new javax.swing.ButtonGroup();
		jTabbedPane1 = new javax.swing.JTabbedPane();
		actionsPanel = new javax.swing.JPanel();
		resetPlayerButton = new javax.swing.JButton();
		sendLogButton = new javax.swing.JButton();
		updatePlayerButton = new javax.swing.JButton();
		restartPlayerButton = new javax.swing.JButton();
		quitPlayerButton = new javax.swing.JButton();
		jLabel17 = new javax.swing.JLabel();
		playerVersionField = new javax.swing.JLabel();
		resetSettings = new javax.swing.JButton();
		resume = new javax.swing.JButton();
		downloadNewPlayerButton = new javax.swing.JButton();
		jLabel15 = new javax.swing.JLabel();
		numErrors = new javax.swing.JLabel();
		configurationsPanel = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		mysqlDatabaseNameTextField = new javax.swing.JTextField();
		mysqlUsernameTextField = new javax.swing.JTextField();
		jLabel4 = new javax.swing.JLabel();
		mysqlServerTextField = new javax.swing.JTextField();
		jLabel5 = new javax.swing.JLabel();
		jLabel6 = new javax.swing.JLabel();
		jLabel7 = new javax.swing.JLabel();
		jLabel8 = new javax.swing.JLabel();
		jLabel9 = new javax.swing.JLabel();
		dmbFtpServerTextField = new javax.swing.JTextField();
		dmbFtpUsernameTextField = new javax.swing.JTextField();
		cancelButton = new javax.swing.JButton();
		saveButton = new javax.swing.JButton();
		jLabel10 = new javax.swing.JLabel();
		jLabel11 = new javax.swing.JLabel();
		jLabel12 = new javax.swing.JLabel();
		jLabel13 = new javax.swing.JLabel();
		jLabel14 = new javax.swing.JLabel();
		boxIdNumberField = new javax.swing.JFormattedTextField();
		scaleNumberField = new javax.swing.JFormattedTextField();
		playerWidthNumberField = new javax.swing.JFormattedTextField();
		playerHeightNumberField = new javax.swing.JFormattedTextField();
		jLabel16 = new javax.swing.JLabel();
		ftpConnectionRadioButton = new javax.swing.JRadioButton();
		httpConnectionRadioButton = new javax.swing.JRadioButton();
		dmbFtpPasswordTextField = new javax.swing.JPasswordField();
		mysqlPasswordTextField = new javax.swing.JPasswordField();
		jLabel18 = new javax.swing.JLabel();
		menuboxRadioButton = new javax.swing.JRadioButton();
		autoboxRadioButton = new javax.swing.JRadioButton();
		jPanel2 = new javax.swing.JPanel();
		jScrollPane1 = new javax.swing.JScrollPane();
		playlistRecordList = new javax.swing.JList();
		jButton1 = new javax.swing.JButton();

		setResizable(false);

		jTabbedPane1.setPreferredSize(new java.awt.Dimension(600, 800));
		jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
			@Override
			public void stateChanged(javax.swing.event.ChangeEvent evt) {
				jTabbedPane1StateChanged(evt);
			}
		});

		resetPlayerButton.setFont(resetPlayerButton.getFont());
		resetPlayerButton.setText("Reset Player");
		resetPlayerButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				resetPlayerButtonActionPerformed(evt);
			}
		});

		sendLogButton.setText("Resend Content");
		sendLogButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				sendLogButtonActionPerformed(evt);
			}
		});

		updatePlayerButton.setFont(updatePlayerButton.getFont());
		updatePlayerButton.setText("Check Update");
		updatePlayerButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				updatePlayerButtonActionPerformed(evt);
			}
		});

		restartPlayerButton.setText("Restart Player");
		restartPlayerButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				restartPlayerButtonActionPerformed(evt);
			}
		});

		quitPlayerButton.setText("Quit Player");
		quitPlayerButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				quitPlayerButtonActionPerformed(evt);
			}
		});

		jLabel17.setText("Player Version: ");

		playerVersionField.setText("version");

		resetSettings.setText("Reset Configurations");
		resetSettings.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				resetSettingsActionPerformed(evt);
			}
		});

		resume.setText("Resume Player");
		resume.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				resumeActionPerformed(evt);
			}
		});

		downloadNewPlayerButton.setText("Download New Player");
		downloadNewPlayerButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				downloadNewPlayerButtonActionPerformed(evt);
			}
		});

		jLabel15.setText("Errors Occured:");

		numErrors.setText("0");

		javax.swing.GroupLayout actionsPanelLayout = new javax.swing.GroupLayout(actionsPanel);
		actionsPanel.setLayout(actionsPanelLayout);
		actionsPanelLayout.setHorizontalGroup(actionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				javax.swing.GroupLayout.Alignment.TRAILING,
				actionsPanelLayout
						.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								actionsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
										.addComponent(resume, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 137,
												Short.MAX_VALUE)
										.addComponent(quitPlayerButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 137,
												Short.MAX_VALUE)
										.addGroup(
												javax.swing.GroupLayout.Alignment.LEADING,
												actionsPanelLayout.createSequentialGroup().addComponent(jLabel17)
														.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(playerVersionField))
										.addComponent(restartPlayerButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE,
												137, Short.MAX_VALUE)
										.addComponent(updatePlayerButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 137,
												Short.MAX_VALUE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								actionsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addGroup(
												actionsPanelLayout
														.createSequentialGroup()
														.addGroup(
																actionsPanelLayout
																		.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
																		.addGroup(
																				actionsPanelLayout
																						.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
																						.addComponent(sendLogButton, javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																						.addComponent(resetSettings,
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																						.addComponent(resetPlayerButton,
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE))
																		.addComponent(downloadNewPlayerButton, javax.swing.GroupLayout.DEFAULT_SIZE, 146,
																				Short.MAX_VALUE)).addGap(731, 731, 731))
										.addGroup(
												actionsPanelLayout.createSequentialGroup().addComponent(jLabel15)
														.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(numErrors)
														.addGap(785, 785, 785)))));
		actionsPanelLayout.setVerticalGroup(actionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				actionsPanelLayout
						.createSequentialGroup()
						.addGap(14, 14, 14)
						.addGroup(
								actionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel17)
										.addComponent(playerVersionField).addComponent(jLabel15).addComponent(numErrors))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addGroup(
								actionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(updatePlayerButton)
										.addComponent(resetPlayerButton))
						.addGap(18, 18, 18)
						.addGroup(
								actionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(resetSettings)
										.addComponent(restartPlayerButton))
						.addGap(18, 18, 18)
						.addGroup(
								actionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(quitPlayerButton)
										.addComponent(sendLogButton))
						.addGap(18, 18, 18)
						.addGroup(
								actionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(resume)
										.addComponent(downloadNewPlayerButton)).addContainerGap(526, Short.MAX_VALUE)));

		jTabbedPane1.addTab("Actions", actionsPanel);

		configurationsPanel.setPreferredSize(new java.awt.Dimension(600, 800));

		jLabel1.setText("Database Name:");

		jLabel2.setText("Database Username:");

		jLabel3.setText("Database Password:");

		mysqlDatabaseNameTextField.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				mysqlDatabaseNameTextFieldActionPerformed(evt);
			}
		});

		mysqlUsernameTextField.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				mysqlUsernameTextFieldActionPerformed(evt);
			}
		});

		jLabel4.setText("Database Server:");

		mysqlServerTextField.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				mysqlServerTextFieldActionPerformed(evt);
			}
		});

		jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
		jLabel5.setText("Database Configuration");

		jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
		jLabel6.setText("Webtool FTP Configuration");

		jLabel7.setText("Ftp Server:");

		jLabel8.setText("Ftp User:");

		jLabel9.setText("Ftp Password:");

		dmbFtpServerTextField.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				dmbFtpServerTextFieldActionPerformed(evt);
			}
		});

		dmbFtpUsernameTextField.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				dmbFtpUsernameTextFieldActionPerformed(evt);
			}
		});

		cancelButton.setText("Cancel");
		cancelButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cancelButtonActionPerformed(evt);
			}
		});

		saveButton.setText("OK");
		saveButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				saveButtonActionPerformed(evt);
			}
		});

		jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14));
		jLabel10.setText("Player Configuration");

		jLabel11.setText("Box Id:");

		jLabel12.setText("Scale:(0.1-1.0)");

		jLabel13.setText("Player Width:");

		jLabel14.setText("Player Height:");

		boxIdNumberField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(
				new java.text.DecimalFormat("#0"))));

		scaleNumberField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat(
				"#0.000"))));

		playerWidthNumberField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(
				new java.text.DecimalFormat("#0"))));
		playerWidthNumberField.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				playerWidthNumberFieldActionPerformed(evt);
			}
		});

		playerHeightNumberField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(
				new java.text.DecimalFormat("#0"))));

		jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14));
		jLabel16.setText("Select File Transfer Protocol");

		ftpConnectionRadioButton.setText("FTP");

		httpConnectionRadioButton.setText("HTTP");

		dmbFtpPasswordTextField.setText("jPasswordField1");
		dmbFtpPasswordTextField.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				dmbFtpPasswordTextFieldActionPerformed(evt);
			}
		});

		mysqlPasswordTextField.setText("jPasswordField1");

		jLabel18.setFont(new java.awt.Font("Tahoma", 1, 14));
		jLabel18.setText("Select Box Type");

		menuboxRadioButton.setText("Menubox");
		menuboxRadioButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				menuboxRadioButtonActionPerformed(evt);
			}
		});

		autoboxRadioButton.setText("Autobox");
		autoboxRadioButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				autoboxRadioButtonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout configurationsPanelLayout = new javax.swing.GroupLayout(configurationsPanel);
		configurationsPanel.setLayout(configurationsPanelLayout);
		configurationsPanelLayout
				.setHorizontalGroup(configurationsPanelLayout
						.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								configurationsPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												configurationsPanelLayout
														.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
														.addComponent(jLabel18, javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																configurationsPanelLayout
																		.createSequentialGroup()
																		.addGroup(
																				configurationsPanelLayout
																						.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								configurationsPanelLayout.createSequentialGroup()
																										.addComponent(ftpConnectionRadioButton)
																										.addGap(18, 18, 18)
																										.addComponent(httpConnectionRadioButton))
																						.addComponent(jLabel16)).addGap(152, 152, 152)))
										.addContainerGap(677, Short.MAX_VALUE))
						.addGroup(
								configurationsPanelLayout.createSequentialGroup().addContainerGap().addComponent(jLabel10)
										.addContainerGap(879, Short.MAX_VALUE))
						.addGroup(
								configurationsPanelLayout.createSequentialGroup().addContainerGap().addComponent(menuboxRadioButton)
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(autoboxRadioButton)
										.addContainerGap(888, Short.MAX_VALUE))
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								configurationsPanelLayout
										.createSequentialGroup()
										.addGroup(
												configurationsPanelLayout
														.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
														.addGroup(
																configurationsPanelLayout.createSequentialGroup().addContainerGap().addComponent(saveButton)
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(cancelButton))
														.addGroup(
																configurationsPanelLayout
																		.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
																		.addGroup(
																				configurationsPanelLayout
																						.createSequentialGroup()
																						.addGap(38, 38, 38)
																						.addGroup(
																								configurationsPanelLayout
																										.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.TRAILING)
																										.addComponent(jLabel14).addComponent(jLabel13)
																										.addComponent(jLabel11).addComponent(jLabel12))
																						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																						.addGroup(
																								configurationsPanelLayout
																										.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																										.addComponent(playerHeightNumberField,
																												javax.swing.GroupLayout.DEFAULT_SIZE, 232,
																												Short.MAX_VALUE)
																										.addComponent(playerWidthNumberField,
																												javax.swing.GroupLayout.DEFAULT_SIZE, 232,
																												Short.MAX_VALUE)
																										.addComponent(scaleNumberField,
																												javax.swing.GroupLayout.DEFAULT_SIZE, 232,
																												Short.MAX_VALUE)
																										.addComponent(boxIdNumberField,
																												javax.swing.GroupLayout.DEFAULT_SIZE, 232,
																												Short.MAX_VALUE)))
																		.addGroup(
																				configurationsPanelLayout
																						.createSequentialGroup()
																						.addContainerGap()
																						.addGroup(
																								configurationsPanelLayout
																										.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.TRAILING)
																										.addComponent(jLabel5,
																												javax.swing.GroupLayout.Alignment.LEADING)
																										.addGroup(
																												javax.swing.GroupLayout.Alignment.LEADING,
																												configurationsPanelLayout
																														.createSequentialGroup()
																														.addGroup(
																																configurationsPanelLayout
																																		.createParallelGroup(
																																				javax.swing.GroupLayout.Alignment.TRAILING)
																																		.addComponent(jLabel4)
																																		.addComponent(jLabel2)
																																		.addComponent(jLabel3)
																																		.addComponent(jLabel1))
																														.addPreferredGap(
																																javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																														.addGroup(
																																configurationsPanelLayout
																																		.createParallelGroup(
																																				javax.swing.GroupLayout.Alignment.LEADING)
																																		.addComponent(
																																				mysqlPasswordTextField,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				232,
																																				Short.MAX_VALUE)
																																		.addComponent(
																																				mysqlUsernameTextField,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				232,
																																				Short.MAX_VALUE)
																																		.addComponent(
																																				mysqlDatabaseNameTextField,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				232,
																																				Short.MAX_VALUE)
																																		.addComponent(
																																				mysqlServerTextField,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				232,
																																				Short.MAX_VALUE)))
																										.addGroup(
																												javax.swing.GroupLayout.Alignment.LEADING,
																												configurationsPanelLayout
																														.createSequentialGroup()
																														.addGap(2, 2, 2)
																														.addGroup(
																																configurationsPanelLayout
																																		.createParallelGroup(
																																				javax.swing.GroupLayout.Alignment.TRAILING)
																																		.addComponent(jLabel8)
																																		.addComponent(jLabel9)
																																		.addComponent(jLabel7))
																														.addPreferredGap(
																																javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																														.addGroup(
																																configurationsPanelLayout
																																		.createParallelGroup(
																																				javax.swing.GroupLayout.Alignment.LEADING,
																																				false)
																																		.addComponent(
																																				dmbFtpPasswordTextField)
																																		.addComponent(
																																				dmbFtpUsernameTextField)
																																		.addComponent(
																																				dmbFtpServerTextField,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				262,
																																				Short.MAX_VALUE)))
																										.addComponent(jLabel6,
																												javax.swing.GroupLayout.Alignment.LEADING)))))
										.addGap(677, 677, 677)));
		configurationsPanelLayout.setVerticalGroup(configurationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				configurationsPanelLayout
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(jLabel6)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(dmbFtpServerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel7))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(dmbFtpUsernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel8))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(jLabel9)
										.addComponent(dmbFtpPasswordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(jLabel5)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(jLabel4)
										.addComponent(mysqlServerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(mysqlDatabaseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel1))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(mysqlUsernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel2))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(jLabel3)
										.addComponent(mysqlPasswordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE))
						.addGap(3, 3, 3)
						.addComponent(jLabel10)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(jLabel11)
										.addComponent(boxIdNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(jLabel12)
										.addComponent(scaleNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(jLabel13)
										.addComponent(playerWidthNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(jLabel14)
										.addComponent(playerHeightNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(jLabel16)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								configurationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(ftpConnectionRadioButton).addComponent(httpConnectionRadioButton))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(jLabel18)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addGroup(
								configurationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(menuboxRadioButton)
										.addComponent(autoboxRadioButton))
						.addGap(11, 11, 11)
						.addGroup(
								configurationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(cancelButton)
										.addComponent(saveButton)).addGap(208, 208, 208)));

		jTabbedPane1.addTab("Configurations", configurationsPanel);

		jPanel2.addComponentListener(new java.awt.event.ComponentAdapter() {
			@Override
			public void componentShown(java.awt.event.ComponentEvent evt) {
				jPanel2ComponentShown(evt);
			}
		});

		jScrollPane1.setViewportView(playlistRecordList);

		jButton1.setText("DELETE");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				jPanel2Layout
						.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1010, Short.MAX_VALUE)
										.addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)).addContainerGap()));
		jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				jPanel2Layout.createSequentialGroup().addContainerGap()
						.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 647, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton1).addContainerGap(24, Short.MAX_VALUE)));

		jTabbedPane1.addTab("Playlist Records", jPanel2);

		getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void mysqlDatabaseNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_mysqlDatabaseNameTextFieldActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_mysqlDatabaseNameTextFieldActionPerformed

	private void mysqlUsernameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_mysqlUsernameTextFieldActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_mysqlUsernameTextFieldActionPerformed

	private void mysqlServerTextFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_mysqlServerTextFieldActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_mysqlServerTextFieldActionPerformed

	private void dmbFtpServerTextFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_dmbFtpServerTextFieldActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_dmbFtpServerTextFieldActionPerformed

	private void dmbFtpUsernameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_dmbFtpUsernameTextFieldActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_dmbFtpUsernameTextFieldActionPerformed

	private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveButtonActionPerformed
		if (this.ftpConnectionRadioButton.isSelected()) {
			Settings.setConnectionType(Settings.FTP_CONNECTION);
		} else {
			Settings.setConnectionType(Settings.HTTP_CONNECTION);
		}
		if (!Settings.getLocalMysqlServer().equals(this.mysqlServerTextField.getText())
				|| !Settings.getLocalMysqlDatabase().equals(this.mysqlDatabaseNameTextField.getText())
				|| !Settings.getLocalMysqlUsername().equals(this.mysqlUsernameTextField.getText())
				|| !Settings.getLocalMysqlPassword().equals(this.mysqlPasswordTextField.getText())
				|| !Settings.getWebtoolFtpHost().equals(this.dmbFtpServerTextField.getText())
				|| !Settings.getWebtoolFtpUser().equals(this.dmbFtpUsernameTextField.getText())
				|| !Settings.getWebtoolFtpPassword().equals(this.dmbFtpPasswordTextField.getText())
				|| Settings.getBoxId() != Integer.parseInt(this.boxIdNumberField.getText())
				|| Settings.getPlayerWidth() != Integer.parseInt(this.playerWidthNumberField.getText())
				|| Settings.getPlayerHeight() != Integer.parseInt(this.playerHeightNumberField.getText())
				|| Settings.getScale() != Double.parseDouble(this.scaleNumberField.getText()) || this.ftpConnectionRadioButton.isSelected()) {

			if (Settings.getBoxId() != Integer.parseInt(this.boxIdNumberField.getText())) {
				Settings.setBlankPlayer(true);
			}
			Settings.setLocalMysqlServer(this.mysqlServerTextField.getText());
			Settings.setLocalMysqlDatabase(this.mysqlDatabaseNameTextField.getText());
			Settings.setLocalMysqlUsername(this.mysqlUsernameTextField.getText());
			Settings.setLocalMysqlPassword(this.mysqlPasswordTextField.getText());
			Settings.setWebtoolFtpHost(this.dmbFtpServerTextField.getText());
			Settings.setWebtoolFtpUser(this.dmbFtpUsernameTextField.getText());
			Settings.setWebtoolFtpPassword(this.dmbFtpPasswordTextField.getText());
			Settings.setBoxId(Integer.parseInt(this.boxIdNumberField.getText()));
			Settings.setScale(Double.parseDouble(this.scaleNumberField.getText()));
			Settings.setPlayerHeight(Integer.parseInt(this.playerHeightNumberField.getText()));
			Settings.setPlayerWidth(Integer.parseInt(this.playerWidthNumberField.getText()));
			Settings.save();
			JOptionPane.showMessageDialog(this, "Settings Saved!\n");
			Player.getInstance().setPaused(false);
			this.dispose();

			CommandFactory.getInstance().restartPlayer();
		} else {
			Player.getInstance().setPaused(false);
			this.dispose();
		}
	}// GEN-LAST:event_saveButtonActionPerformed

	private void playerWidthNumberFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_playerWidthNumberFieldActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_playerWidthNumberFieldActionPerformed

	private void resetPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_resetPlayerButtonActionPerformed
		Settings.setBlankPlayer(true);
		Settings.save();
		Command.resetPlayer();
		CommandFactory.getInstance().restartPlayer();

	}// GEN-LAST:event_resetPlayerButtonActionPerformed

	private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed
		// TODO add your handling code here:
		Player.getInstance().setPaused(false);
		this.dispose();

	}// GEN-LAST:event_cancelButtonActionPerformed

	private void quitPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_quitPlayerButtonActionPerformed
		System.exit(0);
	}// GEN-LAST:event_quitPlayerButtonActionPerformed

	private void restartPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_restartPlayerButtonActionPerformed
		CommandFactory.getInstance().restartPlayer();
	}// GEN-LAST:event_restartPlayerButtonActionPerformed

	private void sendLogButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_sendLogButtonActionPerformed
		HttpRequest.resendContent();

	}// GEN-LAST:event_sendLogButtonActionPerformed

	private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_jTabbedPane1StateChanged
		// TODO add your handling code here:
		if (!this.authenticated && this.jTabbedPane1.getSelectedIndex() == 1 && this.jTabbedPane1.isDisplayable()) {
			String result = JOptionPane.showInputDialog(this, "Please input admin password: ");
			if (result != null && result.equals(Settings.getAdminPassword())) {
				this.authenticated = true;
			} else {
				JOptionPane.showMessageDialog(this, "Invalid password, you cannot access the configuration panel.");
				this.jTabbedPane1.setSelectedIndex(0);
			}
		}
	}// GEN-LAST:event_jTabbedPane1StateChanged

	private void updatePlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_updatePlayerButtonActionPerformed
		this.updatePlayerButton.setEnabled(false);
		Thread updaterThread = new Thread() {

			@Override
			public void run() {
				if (Helper.hasNetworkConnection() && UpdateChecker.hasNewUpdate()) {
					boolean result = Initializer.downloadUpdate(true);
					Initializer.executeSqlScriptsFromFolder();
					Initializer.inputCsvFilesToDatabase();
					boolean result2 = Initializer.downloadContents();
					Player.getInstance().update();
					if (result && result2) {
						SwingUtilities.invokeLater(new Runnable() {

							@Override
							public void run() {
								JOptionPane.showMessageDialog(AdminFrame.this, "Update Complete.");
							}
						});

					} else {
						SwingUtilities.invokeLater(new Runnable() {

							@Override
							public void run() {
								JOptionPane.showMessageDialog(AdminFrame.this, "Some errors might have occured during update.");
							}
						});
					}
				} else {
					SwingUtilities.invokeLater(new Runnable() {

						@Override
						public void run() {
							JOptionPane.showMessageDialog(AdminFrame.this, "No update available.");
						}
					});
				}
				Initializer.downloadContents();
				AdminFrame.this.updatePlayerButton.setEnabled(true);
			}
		};
		updaterThread.start();
	}// GEN-LAST:event_updatePlayerButtonActionPerformed

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
		List<Integer> recordIds = new ArrayList<Integer>();
		for (Object o : this.playlistRecordList.getSelectedValues()) {
			PlaylistRecord record = (PlaylistRecord) o;
			recordIds.add(new Integer(record.getId()));

		}
		if (recordIds.size() == 0) {
			JOptionPane.showMessageDialog(this, "Please select a record to delete.");
		} else {
			int result = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete the playlist record(s) ?");
			if (result == JOptionPane.YES_OPTION) {
				try {
					String ids = "";
					for (int i = 0; i < recordIds.size(); i++) {
						ids += recordIds.get(i);
						if (i != recordIds.size() - 1) {
							ids += ",";
						}
					}
					Helper.localMysqlExecute("DELETE FROM playlist_record where playlist_record_id in (" + ids + ");");
					Player.getInstance().update();
					this.playlistRecordList.setListData(Player.getInstance().getRecords().toArray());
				} catch (SQLException ex) {
					Logger.getLogger(AdminFrame.class.getName()).log(Level.SEVERE, null, ex);
				}
			}
		}
	}// GEN-LAST:event_jButton1ActionPerformed

	private void jPanel2ComponentShown(java.awt.event.ComponentEvent evt) {// GEN-FIRST:event_jPanel2ComponentShown
		Player p = Player.getInstance();
		this.playlistRecordList.setListData(p.getRecords().toArray());
		PlaylistRecordRenderer renderer = new PlaylistRecordRenderer();
	}// GEN-LAST:event_jPanel2ComponentShown

	private void resetSettingsActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_resetSettingsActionPerformed
	}// GEN-LAST:event_resetSettingsActionPerformed

	private void resumeActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_resumeActionPerformed
		Player.getInstance().setPaused(false);
		this.pinPlayerCanvasToTop();
		this.dispose();
	}// GEN-LAST:event_resumeActionPerformed

	private void dmbFtpPasswordTextFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_dmbFtpPasswordTextFieldActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_dmbFtpPasswordTextFieldActionPerformed

	private void downloadNewPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_downloadNewPlayerButtonActionPerformed
		NewPlayerChecker.downloadNewPlayer();
	}// GEN-LAST:event_downloadNewPlayerButtonActionPerformed

	private void autoboxRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_autoboxRadioButtonActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_autoboxRadioButtonActionPerformed

	private void menuboxRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_menuboxRadioButtonActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_menuboxRadioButtonActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		Settings.load();
		java.awt.EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				new AdminFrame().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JPanel actionsPanel;
	private javax.swing.JRadioButton autoboxRadioButton;
	private javax.swing.JFormattedTextField boxIdNumberField;
	private javax.swing.ButtonGroup buttonGroup1;
	private javax.swing.ButtonGroup buttonGroup2;
	private javax.swing.JButton cancelButton;
	private javax.swing.JPanel configurationsPanel;
	private javax.swing.ButtonGroup connectionGroup;
	private javax.swing.JPasswordField dmbFtpPasswordTextField;
	private javax.swing.JTextField dmbFtpServerTextField;
	private javax.swing.JTextField dmbFtpUsernameTextField;
	private javax.swing.JButton downloadNewPlayerButton;
	private javax.swing.JRadioButton ftpConnectionRadioButton;
	private javax.swing.JRadioButton httpConnectionRadioButton;
	private javax.swing.JButton jButton1;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel10;
	private javax.swing.JLabel jLabel11;
	private javax.swing.JLabel jLabel12;
	private javax.swing.JLabel jLabel13;
	private javax.swing.JLabel jLabel14;
	private javax.swing.JLabel jLabel15;
	private javax.swing.JLabel jLabel16;
	private javax.swing.JLabel jLabel17;
	private javax.swing.JLabel jLabel18;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JLabel jLabel9;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTabbedPane jTabbedPane1;
	private javax.swing.JRadioButton menuboxRadioButton;
	private javax.swing.JTextField mysqlDatabaseNameTextField;
	private javax.swing.JPasswordField mysqlPasswordTextField;
	private javax.swing.JTextField mysqlServerTextField;
	private javax.swing.JTextField mysqlUsernameTextField;
	private javax.swing.JLabel numErrors;
	private javax.swing.JFormattedTextField playerHeightNumberField;
	private javax.swing.JLabel playerVersionField;
	private javax.swing.JFormattedTextField playerWidthNumberField;
	private javax.swing.JList playlistRecordList;
	private javax.swing.JButton quitPlayerButton;
	private javax.swing.JButton resetPlayerButton;
	private javax.swing.JButton resetSettings;
	private javax.swing.JButton restartPlayerButton;
	private javax.swing.JButton resume;
	private javax.swing.JButton saveButton;
	private javax.swing.JFormattedTextField scaleNumberField;
	private javax.swing.JButton sendLogButton;
	private javax.swing.JButton updatePlayerButton;

	// End of variables declaration//GEN-END:variables

	public void pinPlayerCanvasToTop() {
		this.setAlwaysOnTop(false);
		PlayerCanvas.getInstance().setAlwaysOnTop(true);
		PlayerCanvas.getInstance().toFront();
		PlayerCanvas.getInstance().setAlwaysToFront(true);
		PlayerCanvas.getInstance().pinToFront();
	}

	@Override
	public void windowOpened(WindowEvent e) {
		System.out.println("admin frame is open");
		setComponentValues();
		PlayerCanvas.getInstance().setAlwaysToFront(false);
		jTabbedPane1.setSelectedIndex(0);
		this.toFront();
	}

	@Override
	public void windowClosing(WindowEvent e) {
		System.out.println("admin window is closed");
		this.pinPlayerCanvasToTop();
	}

	@Override
	public void windowClosed(WindowEvent e) {
	}

	@Override
	public void windowIconified(WindowEvent e) {
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
	}

	@Override
	public void windowActivated(WindowEvent e) {
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		this.setAlwaysOnTop(false);
	}

	@Override
	public void updateChanges() {
	}
}

class PlaylistRecordRenderer extends JPanel implements ListCellRenderer {

	private JLabel text;
	private JButton deleteButton;

	public PlaylistRecordRenderer() {
		this.text = new JLabel("asdf");
		this.deleteButton = new JButton("delete");
		this.add(text);
		this.add(deleteButton);
		this.deleteButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println("DELETE");
			}
		});
		this.setPreferredSize(new Dimension(200, 40));

	}

	/*
	 * This method finds the image and text corresponding to the selected value
	 * and returns the label, set up to display the text and image.
	 */
	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		// Get the selected index. (The index param isn't
		// always valid, so just use the value.)
		// int selectedIndex = ((Integer)value).intValue();
		this.text.setText(value.toString());
		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}

		// Set the icon and text. If icon was null, say so.
		return this;
	}
}
